package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.ParseHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;

/**
 * 百分数
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class LatexPercent extends LatexNumber {
    /**
     * 50.56%  value = 50.56
     */
    private BigDecimal value;

    public String getLatex() {
        return value + "\\%";
    }

    public String getScalePercent(int scale) {
        var scalePercent = value.setScale(scale);
        return scalePercent + "\\%";
    }

    public LatexPercent(BigDecimal value) {
        this.value = value;
    }

    public LatexPercent(String content) {
        var text = content.replace("\\%", "");
        text = content.replace("%", "");
        this.value = ParseHelper.parseBigDecimal(text);
    }

}
